package cc.mycraft.pvp;

import org.bukkit.entity.*;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

public class Achievement {
	
	
	//成就系统，达成一定条件，给玩家权限或物品(执行指令)
	public static void checkKillAchievement(Player p,int Kill,int Combo,int Point) {
		int Death = PlayerManager.getDeathAmount(p);
		double KD = (double)Kill/(double)Death;

		checkKillsAchievement(p,Kill,100,"§dx 百人斩","nKill100","&d&lx");
		checkKillsAchievement(p,Kill,1000,"§ex 千人斩","nKill1000","&e&lx");
		checkKillsAchievement(p,Kill,10000,"§6X 万人斩","nKill10000","&6&lX");
		checkComboAchievement(p,Combo,3,"§ds 斗士新星","nCombo3","&ds");
		checkComboAchievement(p,Combo,5,"§es 角斗大师","nCombo5","&es");
		checkComboAchievement(p,Combo,8,"§6S 斗宗强者","nCombo8","&6S");
		checkComboAchievement(p,Combo,11,"§cS 战神再世","nCombo11","&cS");
		checkPointAchivement(p,Point,100,"§9L1 青铜勇士","nPoint100","&9&lL1");
		checkPointAchivement(p,Point,500,"§dL2 白银斗士","nPoint500","&d&lL2");
		checkPointAchivement(p,Point,1000,"§eL3 黄金猛者","nPoint1000","&e&lL3");
		checkPointAchivement(p,Point,2000,"§eL4 白金战士","nPoint2000","&e&lL4");		
		checkPointAchivement(p,Point,3500,"§6L5 钻石统帅","nPoint3500","&6&lL5");		
		checkPointAchivement(p,Point,6000,"§cL6 战场大师","nPoint6000","&c&lL6");		
		checkPointAchivement(p,Point,10000,"§4L7 竞技天王","nPoint10000","&4&lL7");
		checkKDAchivement(p,KD,2.33,Death,100,"§d身经百战 见得多了","nPVPSuperMan1","&d&lZ");
		checkKDAchivement(p,KD,3.66,Death,1000,"§e图样图森破 上台拿衣服","nPVPSuperMan2","&e&lZ");
		checkKDAchivement(p,KD,4.77,Death,3000,"§6竞技场元老","nPVPSuperMan3","&6&lZ");
	}
	public static void checkDeathAchievement(Player p) {
		int Death = PlayerManager.getDeathAmount(p);
		checkDeathAchievement(p,Death,9,"§d☠ 风水轮流转","nDeath9","&d&lKo");
		checkDeathAchievement(p,Death,99,"§e☠ 常回家看看","nDeath99","&e&lKo");
		checkDeathAchievement(p,Death,999,"§6☠ 这就是命","nDeath999","&6&lKo");
	}

	
	private static void checkKillsAchievement(Player p,int PlayerKill,int KillAmount,String AcheivementName,String Permission,String suffix) {
		if(PlayerKill>KillAmount&&!p.hasPermission(Permission)) {
			Title t = new Title(AcheivementName, "§e达成成就", 5, 40, 5);
			t.send(p);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" add "+Permission);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" suffix "+suffix+"&7·");
		}
	}
	private static void checkComboAchievement(Player p,int PlayerCombo,int ComboAmount,String AcheivementName,String Permission,String suffix) {
		if(PlayerCombo>ComboAmount&&!p.hasPermission(Permission)) {
			Title t = new Title(AcheivementName, "§e达成成就", 5, 40, 5);
			t.send(p);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" add "+Permission);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" suffix "+suffix+"&7·");
		}
	}
	private static void checkDeathAchievement(Player p,int PlayerDeath,int Death,String AcheivementName,String Permission,String suffix) {
		if(PlayerDeath>Death&&!p.hasPermission(Permission)) {
			Title t = new Title(AcheivementName, "§e达成成就", 5, 40, 5);
			t.send(p);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" add "+Permission);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" suffix "+suffix+"&7·");
			Bukkit.getLogger().info("pex user "+p.getName()+" suffix "+suffix);
		}
	}
	private static void checkPointAchivement(Player p,int PlayerPoint,int Point,String AcheivementName,String Permission,String suffix) {
		if(PlayerPoint>Point&&!p.hasPermission(Permission)) {
			Title t = new Title(AcheivementName, "§e达成成就", 5, 40, 5);
			t.send(p);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" add "+Permission);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" suffix "+suffix+"&7·");
		}
	}
	private static void checkKDAchivement(Player p,double PlayerKD,double KD,int PlayerDeath,int Death,String AcheivementName,String Permission,String suffix) {
		if(PlayerKD>KD&&PlayerDeath>Death&&!p.hasPermission(Permission)) {
			Title t = new Title(AcheivementName, "§e达成成就", 5, 40, 5);
			t.send(p);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" add "+Permission);
			Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user "+p.getName()+" suffix "+suffix+"&7·");
		}
	}
}
